//
//  XDLoginHeaderView.m
//  XDEducation
//
//  Created by apple on 2017/4/5.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XDLoginHeaderView.h"


@interface XDLoginHeaderView ()

/** 背景 */
@property(nonatomic,strong) UIImageView *bgImageView;

/** back butotn */
@property(nonatomic,strong) UIButton *backButton;

/** 注册按钮 */
@property(nonatomic,strong) UIButton *registerBtn;
/** midImage */
@property(nonatomic,strong) UIImageView *midImageView;

/** 描述文字 */
@property(nonatomic,strong) UILabel *textLabel;

@end

@implementation XDLoginHeaderView

-(instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        
        [self addSubview:self.bgImageView];
        [self addSubview:self.backButton];
        [self addSubview:self.registerBtn];
        [self addSubview:self.midImageView];
        [self addSubview:self.textLabel];
        
        [self addClickEvent];
    }
    return self;
}


-(void)addClickEvent{
    
    [_backButton addTarget:self action:@selector(backButtonClickEvent) forControlEvents:UIControlEventTouchUpInside];
    [_registerBtn addTarget:self action:@selector(registerButtonClickEvent) forControlEvents:UIControlEventTouchUpInside];
}

-(void)layoutSubviews{

    [super layoutSubviews];
    
    self.bgImageView.frame = self.frame;
    
    self.backButton.frame = CGRectMake(5, 20, 40, 25);
    self.registerBtn.frame = CGRectMake(ScreenW - 15 - 40, 20, 40, 25);
    
    self.midImageView.frame = CGRectMake(0, 0, self.height/1.7, self.height/1.7);
    self.midImageView.center = self.center;
    
    self.textLabel.frame = CGRectMake(0, self.midImageView.bottom + 10 * ScaleHeight, ScreenW, 30);
    
    
}

-(UIImageView *)bgImageView{

    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc]init];
        _bgImageView.image = [UIImage imageNamed:@"bg_img_default"];
    }
    return _bgImageView;
}

-(UIButton *)backButton{
    
    if (!_backButton) {
        _backButton = [[UIButton alloc]init];
        [_backButton setImage:[UIImage imageNamed:@"nav_icon_back_default"] forState:UIControlStateNormal];

    }
    return _backButton;
}

-(UIButton *)registerBtn{

    if (!_registerBtn) {
        
        _registerBtn = [[UIButton alloc]init];
        [_registerBtn setTitle:@"注册" forState:UIControlStateNormal];
        [_registerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _registerBtn.titleLabel.font = [UIFont systemFontOfSize:16];

    }
    return _registerBtn;
}

-(UIImageView *)midImageView{

    if (!_midImageView) {
        
        _midImageView = [[UIImageView alloc]init];
        
        _midImageView.image = [UIImage imageNamed:@"login_icon_login_default"];
    }
    return _midImageView;
}

-(UILabel *)textLabel{

    if (!_textLabel) {
        
        _textLabel = [[UILabel alloc]init];
        _textLabel.text = @"登    录";
        _textLabel.textColor = [UIColor whiteColor];
        _textLabel.font = [UIFont systemFontOfSize:20];
        _textLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _textLabel;
}


#pragma - mark button Clicked Event
-(void)backButtonClickEvent{

    if (self.backBlock) {
        self.backBlock();
    }
}

-(void)registerButtonClickEvent{

    if (self.registerBlock) {
        self.registerBlock();
    }
}

-(void)setIsRegister:(BOOL)isRegister{
    
    _isRegister = isRegister;
    if (isRegister) {
        
        _registerBtn.hidden = YES;
        _midImageView.image = [UIImage imageNamed:@"register_icon_register_default"];
        _textLabel.text = @"注    册";
        
        
    }
}

-(void)setIsForgetPassword:(BOOL)isForgetPassword{
    
    _isForgetPassword = isForgetPassword;
    
    if (isForgetPassword) {
        
        _registerBtn.hidden = YES;
        _midImageView.image = [UIImage imageNamed:@"login_icon_forget_default"];
        _textLabel.text = @"忘记密码";
    }
    
}


@end
